package com.lck.blogmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lck.blogmanager.common.BasePageReq;
import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.entity.TagEntity;
import com.lck.blogmanager.req.AddTagReq;
import com.lck.blogmanager.req.DeleteTagReq;
import com.lck.blogmanager.service.TagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 标签
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/8 16:35
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tag")
@Slf4j
@CrossOrigin
public class TagController {

    private final TagService tagService;

    /**
     * 添加标签
     * @param req
     * @return
     */
    @PostMapping("/add")
    public Response<Integer> addTag (@RequestBody AddTagReq req){
        Integer id = tagService.addTag(req);
        return Response.success(id);
    }

    /**
     * 删除标签
     * @param req
     * @return
     */
    @PostMapping("/delete")
    public Response<Integer> deleteTag (@RequestBody DeleteTagReq req){
        tagService.deleteTag(req);
        return Response.success();
    }


    /**
     * 标签列表
     * @param req
     * @return
     */
    @PostMapping("/list")
    public Response<Page<TagEntity>> listTag(@RequestBody BasePageReq req){
        Page<TagEntity> result = tagService.listTag(req);
        return Response.success(result);
    }



}
